<?php


namespace app\api\controller;

use app\common\controller\Api;
use think\console\command\optimize\Schema;
use think\Db;
use think\Request;

/**
 * 流程
 */
class Huodong extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    public function getallcate(){

        $list=Db::name('huodong')->order('weigh desc')->select();
        foreach ($list as &$key){
            $key['image']=cdnurl($key['image'],true);
        }
        $this->success('全部分类',$list);

    }

    /**
     *  根据分类查询列表
     */

    public function getalllistby(){

        $id=$this->request->param('id');

        $user=$this->auth->getUser();

        $list=Db::name('huodong_c')->where(['huodong_id'=>$id])->order('time desc')->select();

        $time=strtotime('-3 day');

        foreach ($list as &$key){
            $key['new']=0;
            if ($key['time']>$time){

                $key['new']=1;
                $key['name']=date('m-d',$key['time']).$key['name'];

            }

            $logc['user_id']=$user['id'];
            $logc['find']='huodong'.$key['id'];

            $see=Db::name('see_log')->where($logc)->find();

            $key['look']=0;
            if ($see){
                $key['look']=1;
            }

        }

        $this->success('活动',$list);

    }


    //单个阅读
    public function seeonebyid()
    {
        $user=$this->auth->getUser();

        $id=$this->request->param('id');

        $list=Db::name('huodong_c')->where(['id'=>$id])->find();


        $logc['user_id']=$user['id'];
        $logc['find']='huodong'.$id;
        $logc['desc']=$user['nickname'].'完成了'.$list['name'];
        $logc['time']=time();
        $logc['name']='huodong'.$list['huodong_id'];

        Db::name('see_log')->data($logc)->insert();

        $this->success('操作成功！');
    }


    public function seeallbyid()
    {
        $user=$this->auth->getUser();

        $id=$this->request->param('id');

        $list=Db::name('huodong_c')->where(['huodong_id'=>$id])->select();


        foreach ($list as $k){

            $logc['user_id']=$user['id'];
            $logc['find']='huodong'.$k['id'];

            $find=Db::name('see_log')->where($logc)->find();
            if (!$find){
                $logc['desc']=$user['nickname'].'完成了'.$k['name'];
                $logc['time']=time();
                $logc['name']='huodong'.$k['huodong_id'];

                Db::name('see_log')->data($logc)->insert();

            }

        }




        $this->success('操作成功！');
    }

    //详情
    public function getinfobyid(){

        $user=$this->auth->getUser();
        $id=$this->request->param('id');

        $find=Db::name('huodong_c')->where(['id'=>$id])->find();

        $find['v_link']=cdnurl($find['file'],true);

        $this->success('操作成功',$find);
    }

}

